







//
//  BannerView.m
//  ZQLearn
//
//  Created by macfeel on 2019/6/4.
//  Copyright © 2019 macfeel. All rights reserved.
//


#import "BannerView.h"
#import "SDCycleScrollView.h"
#import "BannerModel.h"

@interface BannerView()<SDCycleScrollViewDelegate>

@property(nonatomic,strong)SDCycleScrollView *cycleView;

@end

@implementation BannerView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
        self.backgroundColor = kBackgroundColor;
        
    }
    return self;
}

-(void)setupUI{
    
    //1添加轮播图
    _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth>320?200:150) delegate:self placeholderImage:nil];
    _cycleView.currentPageDotColor = ThemeBlue;
    _cycleView.pageDotColor = kLightGrayColor;
    _cycleView.autoScrollTimeInterval = 5;
    [self addSubview:_cycleView];
    
}


//轮播图数据设置
-(void)setBannerArray:(NSArray *)bannerArray{
    
    _bannerArray = bannerArray;
    
    NSMutableArray* arr = [NSMutableArray array];
    
//    for (int i=0; i<bannerArray.count; i++) {
//        [arr addObject:bannerArray[i]];
//    }
    for (BannerModel* model in bannerArray) {

        NSString *url = model.imageUrl;

        [arr addObject:url];
    }
    
    _cycleView.imageURLStringsGroup = arr;
    
}

#pragma mrak - SDCycleScrollViewDelegate
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if (_bannerBlock) {
        _bannerBlock(index);
    }
}




@end
